package com.gzy.mylog;

import androidx.fragment.app.Fragment;

import java.util.Objects;

public class BaseFragment extends Fragment {

    public void runOnBackThread(final Runnable runnable, final long millis){
        new Thread(new Runnable(){

            @Override
            public void run() {

                try {
                    Thread.sleep(millis);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                runnable.run();
            }
        }).start();
    }
    public void runOnBackThread(final Runnable runnable){
        runOnBackThread(runnable,0);
    }

    public void runOnUiThread(final Runnable runnable, final long millis){
        runOnBackThread(new Runnable() {
            @Override
            public void run() {
                runOnUiThread(runnable);
            }
        },millis);
    }

    private void runOnUiThread(Runnable runnable) {
        Objects.requireNonNull(getActivity()).runOnUiThread(runnable);
    }
}
